require("../../../../@babel/runtime/helpers/Arrayincludes");

var e = require("../../../../@babel/runtime/helpers/defineProperty"), t = require("../../../../@babel/runtime/helpers/toConsumableArray"), a = getApp().globalData.api, s = getApp();

Page({
    data: {
        zizhuPopup: {
            visible: !1,
            showZiZhu: !0
        },
        afterSaleObj: {
            orderId: null,
            type: 0
        },
        triggered: !1,
        listShow: !1,
        loadingExit: !1,
        listIndex: 'all',
        orderList: [],
        listSelect: [ {
            name: "全部",
            num: 'all'
        }, {
            name: "待付款",
            num: 0
        }, {
            name: "已支付",
            num: 1
        }, 
        // {
        //     name: "待评价",
        //     num: 3
        // }, 
        {
            name: "退款/售后",
            num: 4
        } ]
    },
    onLoad: function(e) {
        var t = e.condition;
        t && this.setData({
            listIndex: t
        });
    },
    onReady: function() {},
    onShow: function(e) {
        (this.data.param || 0 == this.data.orderList.length) && (this.setData({
            orderList: [],
            param: ""
        }), this.dataDefaultArray(1, this.data.listIndex));
    },
    obtainList: function(e) {
        var t = this, a = e.currentTarget.dataset.index;
        if (!t.data.triggered && a != t.data.listIndex && t.data.listShow) {
            t.data.orderList;
            t.setData({
                listIndex: a,
                loadingExit: !1,
                listShow: !1
            }), t.dataDefaultArray(1, a);
        }
    },
    dataDefaultArray: function(e, s) {
        var that = this, para = {
            status: s,
            page: e,
            pageSize: 10,
            openid:wx.getStorageSync('openid')
        }; 
         a.post1("wechat/home/myOrderList", para, !0).then(function(e) {  
            if (that.setData({
                listShow: !0,
                triggered: !1
            }), "1" == e.code) {
                var a = that.data.orderList;
             
                // 1 == e.data.page ? a = e.data : (a.list = [].concat(t(that.data.orderList.list), t(e.data.list)), 
                1 == e.data.page ? a = e.data : (a.list = [].concat(t(that.data.orderList.list), t(e.data.list)), 
                a.page = e.data.page, a.total = e.data.total);
                var s = [];
                console.log(111,a.list);
                a.list.forEach(function(e) {
                    e = that.addTabData(e);
                    var t = 0;
                    // e.gdsItems.forEach(function(e) {
                    //     t += e.gdsNum;
                    // });
                     e.orderPkgNum = t
                    , s.push(e);
                }), 
                
                // a.list = s, a.list.length == that.data.orderList.total ?that.setData({
                a.list = e.data.list, a.list.length == that.data.orderList.total ?that.setData({
                    orderList: a,
                    loadingExit: !0
                }) : that.setData({
                    orderList: a
                });
            }
        }, function(e) {
            r.setData({
                listShow: !0,
                triggered: !1
            });
        });
    },
    getMoreOrder: function() {
        this.data.loadingExit || (this.setData({
            triggered: !0
        }), this.dataDefaultArray(this.data.orderList.pageNum + 1, this.data.listIndex));
    },
    tjxzClick: function() {
        this.tixz = this.selectComponent("#tixz"), this.tixz.show();
    },
    delOrder: function(t) {
        var s = this, r = t.currentTarget.dataset.ord;
        console.log(r), wx.showModal({
            title: "确定删除订单？",
            content: "删除后将无法再查看此订单信息，请谨慎选择；如有问题请拨打客服热线：".concat(getApp().globalData.tel),
            cancelColor: "#999999",
            confirmColor: "#2199FF",
            success: function(t) {
                t.confirm && a.putPort("delOrader", {
                    rest: r
                }, !0).then(function(t) {
                    if (t.values) {
                        var a = s.data.orderList.list;
                        a = a.filter(function(e) {
                            return r != e.id;
                        }), s.setData(e({}, "orderList.list", a)), wx.showToast({
                            icon: "none",
                            title: "删除成功"
                        });
                    }
                }, function(e) {});
            }
        });
    },
    channleSale: function(e) {
        var t = e.currentTarget.dataset.ord;
        console.log(t.id);
        var s = {
            rest: t.id
        }, r = this;
        wx.showModal({
            title: "温馨提示",
            content: "确定取消退款",
            success: function(e) {
                e.confirm ? a.getPort("updateCancelRefundApply", s, "").then(function(e) {
                    r.reminder("取消成功"), r.dataDefaultArray(1, r.data.listIndex);
                }, function(e) {
                    r.reminder(e.data.message[0].message);
                }) : e.cancel && console.log("用户点击取消");
            }
        });
    },
    runAfterSale: function(e) {
        var t = e.currentTarget.dataset.ord, a = e.currentTarget.dataset.type, s = !0;
        t.hasOwnProperty("applyStatus") && ("JG01" == t.applyStatus ? ("BG01" == t.applyType && (this.reminder("该订单已提交申请退款"), 
        s = !1), "BG02" == t.applyType && (this.reminder("该订单已提交申请改期"), s = !1), "BG03" == t.applyType && (this.reminder("该订单已提交申请开票"), 
        s = !1), "BG05" == t.applyType && (this.reminder("该订单已提交取消预约"), s = !1)) : "JG02" == t.applyStatus && t.hasOwnProperty("applyType") && "BG02" != t.applyType && ("BG01" == t.applyType && (this.reminder("该订单已退款"), 
        s = !1), "BG02" == t.applyType && (this.reminder("该订单已改期"), s = !1), "BG03" == t.applyType && (this.reminder("该订单已开票"), 
        s = !1))), s && (this.setData({
            "afterSaleObj.orderId": t.id,
            "afterSaleObj.type": a
        }), 1 == a ? this.handleShow() : this.entertAfterSafe());
    },
    runCannel: function() {
        this.handleShow(!0);
    },
    handleShow: function() {
        var e = arguments.length > 0 && void 0 !== arguments[0] && arguments[0];
        this.setData({
            "zizhuPopup.visible": !0,
            "zizhuPopup.showZiZhu": !e
        });
    },
    handleCancel: function() {
        this.setData({
            "zizhuPopup.visible": !1
        });
    },
    dialogAfterSafeRefundTap: function() {
        this.handleCancel(), this.entertAfterSafe();
    },
    entertAfterSafe: function() {
        var e = "/pages/usercenter/userOrder/order_after_sale/order_after_sale?orderId=" + this.data.afterSaleObj.orderId + "&type=" + this.data.afterSaleObj.type;
        getApp().pushPage(e);
    },
    haveCheckTap: function(t) {
        var s = this, r = t.currentTarget.dataset.ord;
        wx.showModal({
            title: "温馨提示",
            content: "你已完成到院体检了吗？",
            cancelColor: "#999999",
            confirmColor: "#2199FF",
            success: function(t) {
                t.confirm && a.getPort("updateStatus4Complete", {
                    rest: r
                }, !0).then(function(t) {
                    if (t.values) {
                        var a = s.data.orderList.list;
                        a.forEach(function(e, t) {
                            var a = e;
                            a.status = "9015", a.statusName = "已完成", e = s.addTabData(a);
                        }), s.setData(e({}, "orderList.list", a)), s.reminder("提交成功!");
                    }
                }, function(e) {
                    e.data.hasOwnProperty("result") && "ERROR" == e.data.result && wx.showToast({
                        title: e.data.message[0].message || e.data.message[0].code,
                        icon: "none",
                        duration: 2e3,
                        mask: !0
                    });
                });
            }
        });
    },
    reminder: function(e) {
        wx.showToast({
            title: e,
            icon: "none",
            duration: 2e3,
            mask: !0
        });
    },
    buyAgain: function(e) {
        for (var t = e.currentTarget.dataset.gds, a = "", s = "", r = 0; r < t.length; r++) a += "," + t[r].gdsId, 
        s += "," + t[r].gdsNum;
        var n = "/pages/order/place-order/place-order?setId=" + (a = a.substr(1, a.length)) + "&setNumber=" + (s = s.substr(1, s.length));
        getApp().pushPage(n);
    },
    payment: function(e) {
        var t = e.currentTarget.dataset.id;
        this.readPay(t);
    },
    readPay: function(e) {
        var t = '{"openId":"'.concat(wx.getStorageSync("openId"), '"}'), r = {
            orderId: e,
            payChannel: s.globalData.appInfo.payChannel,
            mchId: s.globalData.appInfo.mchId,
            extra: t
        };
        a.postPort("payOrder", r, !0).then(function(t) {
            var a = JSON.parse(t.values);
            console.log(a), wx.requestPayment({
                timeStamp: a.payParams.timeStamp,
                nonceStr: a.payParams.nonceStr,
                package: a.payParams.package,
                signType: a.payParams.signType,
                paySign: a.payParams.paySign,
                success: function(t) {
                    "requestPayment:ok" == t.errMsg && wx.redirectTo({
                        url: "/pages/order/pay_succeed/pay_succeed?orderId=" + e
                    });
                },
                fail: function(e) {
                    wx.showToast({
                        title: "支付失败",
                        icon: "none",
                        duration: 2e3,
                        mask: !0
                    });
                },
                complete: function(e) {}
            });
        }, function(e) {
            e.data.hasOwnProperty("result") && "ERROR" == e.data.result && wx.showToast({
                title: e.data.message[0].message,
                icon: "none",
                duration: 2e3,
                mask: !0
            });
        });
    },
    addTabData: function(e) {
        var t, a = {
            showDelectorder: !1,
            showBuyAgain: !1,
            showCannelOrder: !1,
            showEva: !1,
            showToPayment: !1,
            showToEvaluate: !1,
            showToInvoice: !1,
            showInvoiveDetais: !1,
            showAroundOther: !1,
            showToYuYue: !1,
            showRefund: !1,
            showCannel: !1,
            showChangeTime: !1,
            showInstructions: !1,
            showHaveCheck: !1,
            showCancelRefund: !1,
            showTab: !1
        }, s = [ "9Q17", "9Q19", "9Q21", "9Q70", "9317", "9306", "9A22", "9A20", "9QHS" ].includes(e.platSource);
        if (9016 == e.status) a.showDelectorder = !0, e.gdsItems.length > 0 && (a.showBuyAgain = !0); else if (9001 == e.status) s || (a.showToPayment = !0, 
        a.showCannelOrder = !0); else if (9019 == e.status) s || (a.showCannelOrder = !0); else if (9015 == e.status) a.showDelectorder = !0, 
        [ "9Q19", "9Q21" ].includes(e.platSource) || (e.ifInvoice ? a.showInvoiveDetais = !0 : e.ifSupportInvoice && (a.showToInvoice = !0)), 
        e.gdsItems.length > 0 && !e.evaId && (a.showToEvaluate = !0), e.evaId && (a.showEva = !0), 
        e.gdsItems.length > 0 && (a.showBuyAgain = !0); else if (9008 == e.status) a.showAroundOther = !0, 
        e.gdsItems.length > 0 && (a.showBuyAgain = !0); else if (9018 == e.status && 0 == e.refundAmount) "9A20" == e.kind || "9A05" == e.kind || s || ("9A22" == e.kind ? a.showCannel = !0 : e.ifFrontRefundShow && (a.showRefund = !0)), 
        a.showToYuYue = !0; else if (9006 != e.status && 9007 != e.status) {
            if (9002 == e.status && 0 == e.refundAmount) {
                "9A20" == e.kind || "9A05" == e.kind || s || ("9A22" == e.kind ? a.showCannel = !0 : e.ifFrontRefundShow && (a.showRefund = !0)), 
                s || (a.showChangeTime = !0);
                for (var r = [], n = 0; n < e.gdsItems.length; n++) for (var o = 0; o < e.gdsItems[n].checkers.length; o++) {
                    var i = e.gdsItems[n].checkers[o].bespeakDate;
                    if (i) {
                        var d = i.replace(/[^0-9]/gi, "").substring(0, 8), l = parseInt(d);
                        r.push(l);
                    }
                }
                var u = (t = new Date().toISOString().slice(0, 10).replace(/[^0-9]/gi, "").substring(0, 8), 
                parseInt(t));
                1 == r.every(function(e, t) {
                    return e <= u;
                }) ? (console.log("已到检--显示"), a.showHaveCheck = !0) : (a.showHaveCheck = !1, console.log("已到检--隐藏"));
            }
            a.showInstructions = !0;
        } else "9007" == e.status && e.ifRefund && (a.showCancelRefund = !0);
        for (var h in a) if (a[h]) {
            a.showTab = !0;
            break;
        }
        return e.tabShowDic = a, e;
    },
    onlineTap: function() {
        getApp().onlineKeFuTap({
            pagePath: "/pages/usercenter/my-order/my-order"
        });
    }
});